package com.itggm.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.itggm.DTO.ActivityPageDTO;
import com.itggm.mapper.ActivityMapper;
import com.itggm.pojo.Activity;
import com.itggm.response.ResponseResult;
import com.itggm.service.ActivityService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author: ggm
 * @data 2024年11月19日 13:44
 * 活动管理
 */
@Service
public class ActivityServiceImpl implements ActivityService {
    @Autowired
    private ActivityMapper activityMapper;

    @Override
    public ResponseResult page(ActivityPageDTO activityPageDTO) {

        PageHelper.startPage(activityPageDTO.getPage(), activityPageDTO.getLimit());
        List<Activity> activities =activityMapper.page(activityPageDTO);
        PageInfo<Activity> activityPageInfo = new PageInfo<>(activities);
        return ResponseResult.success().count(activityPageInfo.getTotal()).data(activityPageInfo.getList());
    }

    @Override
    public ResponseResult add(Activity activity) {
        activityMapper.insertActivity(activity);
        return ResponseResult.success();
    }

    @Override
    public ResponseResult delete(List<Integer> ids) {

        activityMapper.deleteActivity(ids);
        return ResponseResult.success();
    }

    @Override
    public ResponseResult selectactivityList(Integer limit) {
        List<Activity> activities =activityMapper.selectactivityList(limit);
        return ResponseResult.success().data(activities);

    }
}
